I. Single responsibility principle Single Responsibility Principle, referred to as SRP. definition There should never be more than one reason for a class to change Guidelines The division of responsibilities? Single definition and level? Should be based on actual business conditions. Focus on change. When it is actually used, it is difficult for the class to have a single responsibility, but the responsibility of the interface should be as simple as possible. II. The principle of replacement on the Richter Liskov Substitution Principle, abbreviated as LSP. definition Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it where all referencing base classes must be able to transparently use objects of their subclasses Guidelines The principle of Leebius substitution defines a specification for good inheritance: Subclass must fully implement the parent method Subclasses can have their own personality (properties and methods). Input parameters can be magnified when overriding or implementing a parent method. When overriding or implementing a parent method, the output can be reduced. Note: Be sure to use parent classes or interfaces when calling other classes in a class. If you cannot use parent classes or interfaces, the design of the class has violated the LSP principle. III. The principle of dependency inversion Dependence Inversion Principle, referred to as DIP definition High level modules should not depend upon low level modules.Both should depend on abstractions.Abstractions should not depend upon details.Details should depend on abstractions. Translated to include three meanings: High-level modules should not rely on lower-level modules, and both should rely on their abstraction Abstraction should not rely on details. Details should rely on abstraction. Streamlined definition: Interface-oriented programming. Cases Test-Driven Development test-driven development is the best embodiment of the dependency on inversion principle. Test-driven development requires that test classes be written first, and tests must be written to implement the classes. This requires that you first think about interface definitions. The three ways to rely on: The constructor passes the dependent object. The Setter method passes the dependent object. The interface declaration depends on the object. Best Practices: Each class has interfaces or abstract classes as much as possible, or both abstract classes and interfaces. The surface type of the variable is an interface or an abstract class as much as possible. No class should derive from a concrete class. Try not to override the base class method. Used in conjunction with the Leeb substitution principle. IV. Interface isolation principle: The interface here refers to the interface defined with the interface keyword. definition: Clients should not be forced to depend upon interfaces that they don't use. (The client should not rely on its unwanted interfaces.) The dependency of one class to anther one should depend on the least possible interface. Should be built on the smallest interface.) Summary: Create a single interface, do not build a large, bloated interface. In layman's terms, the interfaces are as detailed as possible, and the methods in the interface are as small as possible. Guidelines How to refine? What process is detailed? There is no uniform standard, but it should be subdivided according to the business. It is the focus of the business. Guarantee the pureness of the interface: The interface should be as small as possible. The interface should be highly cohesive. Custom service. The design of the interface is limited. Best Practices: An interface only serves a submodule or business logic. Through the public logic in the business logic compression interface, the interface is often reviewed, as far as possible to make the interface to "full of muscle" rather than a "fat" a lot of methods. Interfaces that have been contaminated are modified as much as possible. If the risk of change is large, the adapter mode is used for conversion processing. Understand the environment and refuse to follow blindly. Each project or product has specific environmental factors. Do not blindly follow the design of the master. Do the best interface design based on business logic. V. Demeter Rule Law of Demeter, LOD. Also known as the Least Knowledge Principle (LKP). definition: An object should keep a minimum understanding of other objects. Guidelines: In layman's terms, a class should know least about the classes it needs to couple or call. The complexity of the internals of your (coupled or invoked classes) has nothing to do with me. That's your business. I call you The public method does not care about the other. Low coupling requirements: Only communicate with friends Friend class: A class that appears in the input and output parameters of a member variable or method. The class inside the method body does not belong to the friend class. There is also a distance between friends Dimit's rule requires the class to be shy, try not to publish too many public methods and non-static public variables, try to be as introverted as possible, and use private, package-private, protected, and other access permissions. It’s your own If a method is placed in this class, it does not increase the relationship between classes, but also does not have a negative impact on this class, it is placed in this class. Use Serializable with caution 6. The principle of opening and closing definition: Software entities like classes, modules and functions should be open for extension but closed for modifications. A software entity such as classes, modules, and functions should be open to extensions and closed to modifications. Guidelines: The software entity includes the following sections: Projects and software products are divided into modules according to certain logical rules. Abstraction and class. method. The three types of change: Logic change submodule change visible view change Outdoor Front-service Die-casting Aluminum Led Wall Outdoor Front-Service Die-Casting Aluminum Led Wall,Full Color Advertising Led Wall,Outdoor Fixed Billboards Iron Case,Led Wall Screen Guangzhou Cheng Wen Photoelectric Technology Co., Ltd. , https://www.cwledwall.com